import logging
import os

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager

# 初始化 Flask 应用
app = Flask(__name__)
app.config['SECRET_KEY'] = 'nihaoadsalkxm145'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
app.audio_dir=os.path.join(app.static_folder, 'audio//')
# 初始化扩展
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
# 在 login_manager 配置中使用正确的视图函数名
login_manager = LoginManager(app)
login_manager.login_view = "LoginPage"  # 确保这里使用的是 "LoginPage"
login_manager.login_message_category = 'info'



login_manager.login_message = '请先登录以访问该页面'  # 修改登录提示信息为中文
login_manager.login_message_category = 'warning'  # 设置消息类型


# 配置自定义日志系统
app_logger = logging.getLogger('app_custom')
app_logger.setLevel(logging.INFO)
file_handler = logging.FileHandler('app.log', encoding='utf-8')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
app_logger.addHandler(file_handler)
# 防止日志传递到根记录器
app_logger.propagate = False

# app_logger.info('这是一条自定义日志信息')
# app_logger.error('发生了一个错误')
# 导入路由
from App import routes






# import os
# from flask import Flask
# from flask_sqlalchemy import SQLAlchemy
# from flask_bcrypt import Bcrypt
# from flask_login import LoginManager
#
# app = Flask(__name__)
#
# basedir = os.path.abspath(os.path.dirname(__file__))
# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'instance/data.db')
#
# app.config['SECRET_KEY'] = os.urandom(12).hex()
# app.config['basedir']= basedir
# app.config['mp3']=  os.path.join(basedir, 'static\\mp3\\')
# db = SQLAlchemy(app)
# bcrypt = Bcrypt(app)
# login_manager = LoginManager(app)
# login_manager.login_view = "LoginPage"  # 确保这里使用的是 "LoginPage" 而不是 "login"
# login_manager.login_message_category = 'info'
#
# login_manager.login_message = '请先登录以访问该页面'  # 自定义提示信息
# login_manager.login_message_category = 'warning'  # 设置消息类型
#
#
#
#
#
#
# from App import routes

